package language;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class IteratorTest {
    public static void main(String[] args) {
        List<String> strings = new ArrayList<String>();
        strings.add("Enum");
        strings.add("bbb");
        Iterator<String> iterator = strings.iterator();

        while(iterator.hasNext()) { //如果存在元素的话返回true
            System.out.println(iterator.next());  //iterator.next()返回迭代的下一个元素
            //如果迭代器没有元素了还调用next方法，会报NoSuchElementException错误
//            System.out.println(iterator.next());
//            System.out.println(iterator.next());
        }
    }

}